var _n3;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$yyComponent = require("yyComponent");
var s = cc__importDefault($1$yyComponent);
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_CityNode = function (t) {
  function _ctor() {
    // 初始化一个新对象，若 t 不为 null，则调用 t
    let instance = null !== t && t.apply(this, arguments) || this;

    // 为对象设置默认属性
    instance.cityNode = null;
    instance.scr = null;
    instance.content = null;
    instance.myCityTxt = null;
    instance.dingbujuli = 400; // 设置定步距离
    instance.jianju = 550; // 设置间距
    instance.xianshijuli = 100; // 设置显示距离
    instance._nodeList = []; // 节点列表
    instance.curRSVNum = -1; // 当前 RSV 数量
    instance.cityRankData = []; // 城市排名数据

    return instance;

  }
  cc__extends(_ctor, t);
  _ctor.prototype.start = function () { };
  _ctor.prototype.scrollviewEvent = function () {
    let context = this;
    let scrollView = this.scr;
    let contentNode = this.content;
    let scrollOffsetY = scrollView.getScrollOffset().y;
    let index = Math.floor((scrollOffsetY - this.xianshijuli) / this.jianju);

    if (index >= 0) {
      // 初始化节点列表
      if (this._nodeList.length < 1) {
        contentNode.children.forEach(function (child) {
          if (child.name !== "cityRank") {
            context._nodeList.push(child);
          }
        });
      }

      // 更新城市排名节点
      if (index > this.curRSVNum) {
        updateCityRank(index);
      } else if (index < this.curRSVNum) {
        this._nodeList.reverse();
        let removedNode = this._nodeList.splice(0, 1)[0];
        this._nodeList.push(removedNode);
        this._nodeList.reverse();
        this.curRSVNum = index;
        updateCityRank(index);
      }
    }

    function updateCityRank(startIndex) {
      for (let a = startIndex; a < startIndex + 3; a++) {
        let node = this._nodeList[a - startIndex];
        if (a < 10 && node) {
          node.y = -this.dingbujuli - this.jianju * a;
          let cityNameLabel = node.getChildByName("rank").getChildByName("cityName").getComponent(cc.Label);
          if (cityNameLabel.string !== this.cityRankData[a].cityName) {
            this.showCityInfo(node, this.cityRankData[a]);
          }
        }
      }
    }

  };
  _ctor.prototype.updataCity = function () {
    let context = this;
    let userData = $zqcc_OverallSystem.sers().userSrv.getUserData();
    let userCity = userData.default.getInstance().city;
    let userWinNum = userData.default.getInstance().daywinnum;

    if (userCity === "") {
      context.myCityTxt.string = "您还没有加入地区";
    } else {
      context.cityRankData.forEach(function (cityData) {
        if (cityData.cityName === userCity) {
          if (userWinNum > 0) {
            context.myCityTxt.string = "我的地区排名:第" + cityData.rank + "名";
          } else {
            context.myCityTxt.string = "通关助力地区(当前第" + cityData.rank + "名)";
          }
        }
      });
    }

  };
  _ctor.prototype.showCityInfo = function (t, e) {
    let birdChildren = t.getChildByName("niao").children;
    let rankNode = t.getChildByName("rank");
    t.getChildByName("isMe").active = false;
    let scaleDirection = Math.random() > 0.5 ? -1 : 1;

    // 更新鸟的显示状态和缩放
    birdChildren.forEach(function (bird, index) {
      bird.active = index < e.score;
      bird.scaleX = bird.active ? scaleDirection : 1; // Scale only if active
    });

    // 更新排名相关的 UI
    if (e.rank !== 1) {
      rankNode.getChildByName("no1").active = false;
      rankNode.getChildByName("rankTxt").color = new cc.Color().fromHEX("#000000");
      let tai1Node = t.getChildByName("tai1");
      if (tai1Node) tai1Node.active = true;
    } else {
      rankNode.getChildByName("no1").active = true;
      rankNode.getChildByName("rankTxt").color = new cc.Color().fromHEX("#FFFFFF");
      let tai1Node = t.getChildByName("tai1");
      if (tai1Node) tai1Node.active = false;
    }

    // 更新排名文本和猫的数量文本
    rankNode.getChildByName("rankTxt").getComponent(cc.Label).string = "第" + e.rank + "名";
    rankNode.getChildByName("niaoNum").getComponent(cc.Label).string = e.score + "只猫";

    // 处理城市名称
    let cityName = e.cityName;
    if (cityName.endsWith("省") || cityName.endsWith("市")) {
      cityName = cityName.slice(0, -1);
    }
    rankNode.getChildByName("cityName").getComponent(cc.Label).string = cityName + "舞台";

  };
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "cityNode", undefined);
  cc__decorate([ccp_property(cc.ScrollView)], _ctor.prototype, "scr", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "content", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "myCityTxt", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(s.default);
exports.default = def_CityNode;